/**
 * 数组去重复
 * 
 * @returns {Array}
 */
Array.prototype.redata = function() {
    var n = {}, r = [];
	for (var i = 0; i < this.length; i++) {
		if (!n[this[i]]) {
			n[this[i]] = true;
			r.push(this[i]);
		}
	}
	return r;
};

/**
 * 功能 dom数据绑定|dom数据获取
 * 
 * 使用 $([ele]).dd([data]) 绑定数据 $([ele]).dd() 获取数据
 * 
 * 参数 [ele] 选择器标签 [data] 绑定的数据
 */
$.fn.dd = function(a) {
	if (this.length == 0)
		throw 'this length 0.'
	var key = 'binddata';
	if (!a)
		return this[0][key];
	this[0][key] = a;
};


$.fn.ap = function(a, b) {
	var re = /{#.+?}/g;
	/* 获取代码占位符 */
	var keys = a.match(re).redata();
	/* 遍历数据 */
	for (var i = 0; i < b.length; i++) {
		var data = b[i], code = a;
		/* 替换占位符 */
		for (var j = 0; j < keys.length; j++) {
			var k = keys[j];
			var key = k.replace(/{#|}/g, '');
			var value = eval('data.'+key);
			var keyre = RegExp(k.replace(/\(/g,'\\(').replace(/\)/g,'\\)'), 'g');
			code = code.replace(keyre, value==null?'-':value);
		}
		var $code = $(code);
		/* 绑定数据,追加到dom */
		$code.dd(data);
		this.append($code);
	}

};
